<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 入门</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <h2>Vue 起步学习</h2>
        <h3>hello Vue</h3>
        <h4 v-on:click="countadd(10)">count -- {{ count }}</h4>
        <h4>msg -- {{msg}}</h4>
        <h4>word -- {{word}}</h4>
        <div data-id="2105" class="box" v-bind:data-title="txt">
            {{txt}}
        </div>
        <div v-if="flag">
            <img v-bind:src="imgSrc" width="200" height="200" alt="">
            <a v-bind:href="link">百度一下你就知道</a>
            <h2>v-if 空值元素的显示和隐藏</h2>
        </div>
        <button v-on:click="changeFlag">点击切换</button>
        <h3 v-show="show">v-show也能空值元素的显示和隐藏</h3>
        <h3 v-show="!show">已变结果</h3>
        <button v-on:click="changeShow">show change</button>
        <p v-for="(l,i) in list">
            {{l}} -{{i}}
        </p>


        <!-- 数据双向绑定  只能绑定给输入框 -->
        <input type="text" v-model="message">
        <h4 v-once="message">{{message}}</h4>

        <input type="text" v-model="userName">
        <h4 v-text="userName"></h4>
        <div v-html="html">
            <!-- 测试 -->
        </div>
    </div>
</body>
<script>

    // Property or method "words" is not defined on the instance but referenced during render
    // 报错:未定义
    console.log(Vue);
    const vm = new Vue({
        el: "#app",
        data: {
            count: 2105,
            msg: "wh2105-daydayup",
            word: "Vue .js 的核心是一个允许才用简介的模板语法来声明式的将数据渲染进DOM的系统",
            txt: "离毕业还剩8周",
            imgSrc: "https://d302.paixin.com/thumbs/11433294/154255056/staff_1024.jpg?imageView2/2/interlace/1/w/250/h/375",
            link: "https://www.baidu.com",
            flag: true,
            show: true,
            list: ["Vue", "react", "Angular", "TypeScript", "Webpack", "Node"],
            message: "Are you ok?",
            userName: "柯南",
            html: "<h1>今天晚上吃啥子</h1>"
        },
        methods: {
            changeFlag() {
                this.flag = !this.flag
            },
            changeShow() {
                this.show = !this.show
            },
            countadd(n) {
                this.count += n
            }
        }
    })
</script>

</html>